<?php
/* +----------------------------------------------------------------------
// | 	xaoam.com
// |	author:am
// |	gitee:https://gitee.com/xaoam/amAdmin
// |	email:hi@xaoam.com
// |	
// +----------------------------------------------------------------------*/
namespace app\admin\model;

use think\Model;
use think\Db;
use app\admin\validate\Tag as TagCheck;

class TagM extends Model {
	protected $table = "am_tag";
	      
		/*验证器,验证*/
	protected function checkData($act,$data){
		$check = new TagCheck;
		if (!$check->scene($act)->check($data)) {
			$res['msg'] = $check->getError();
			$res['code'] = 0;
			header('Content-type:application/json; charset=utf-8');
			echo json_encode($res);
			exit();
		}
	}
	public function lists($type=1){
		return $this->where('type',$type)->select();
	}
	public function find($data){
			return $this->where($data)->find();
	}
	public function edit($data){
		$this->checkData('edit',$data);
		$data['status'] = isset($data['status'])?1:0;
		return $this->update($data);
	}
	public function add($data){
		$this->checkData('add',$data);
		$data['status'] = isset($data['status'])?1:0;
		return $this->allowField('true')->create($data);
	}
	public function del($data){
		
		if(is_array($data['id'])){
			foreach($data['id'] as $row){
				$arr['id'] = $row;
				$this->checkData('del',$arr);
			}
		}else{
			$this->checkData('del',$data);
		}
		return $this->destroy($data['id']);
	}	
}	